package squareBorderPackage;

import be.kuleuven.cs.som.annotate.*;

/**
 * A class of walls that can be slippery involving two squares in two opposed directions.
 * 
 * @author	Jessa Bekker & Esther Alberts
 * @version	2.0
 */
public class Wall extends Border {

	/**
	 * Initialize this new wall with given slippery.
	 * 
	 * @param slippery
	 *            The initial value for the slippery state of this new wall.
	 */public Wall(boolean slippery, Square square, Direction direction) {
		super(square, direction);
		this.slippery = slippery;
	}

	/**
	 * Return whether this wall is slippery or not.
	 */
	@Override @Basic
	public boolean getSlippery() {
		return slippery;
	}

	/**
	 * Variable registering whether the door is slippery or not.
	 */
	public final boolean slippery;

	/**
	 * Return whether this wall is an obstacle or not.
	 * 
	 * @return result==true;
	 */
	@Override
	public boolean isObstacle() {
		return true;
	}

	/**
	 * @return This border if the other border is not effective | if (other ==
	 *         null) | then (result == this)
	 * @return The other border if the other border is a wall and this wall is
	 *         slippery. |if (other instanceof Wall && this.getSlippery()) |
	 *         then (result == other)
	 * @return This border if the other Border is a wall and this wall is not
	 *         slippery |if (other instanceof Wall && ! this.getSlippery()) |
	 *         then (result == this)
	 * @return This border if the other border is a open border. |if (other
	 *         instanceof OpenBorder) | then (result == this)
	 * @return This border if the other border is a door. |if (other instanceof
	 *         Door) | then (result == this)
	 * @return The strongest border of the other border and this border in all
	 *         other cases. |if (! (other == null || | other instanceof Wall ||
	 *         | other instanceof OpenBorder || | other instanceof Door)) | then
	 *         (result == other.getStrongestBorder(this)
	 */
	@Override
	public Border getStrongestBorder(Border other) {
		if (other == null)
			return this;
		if (other instanceof Wall) {
			if (this.getSlippery())
				return other;
			return this;
		}
		if (other instanceof OpenBorder)
			return this;
		if (other instanceof Door)
			return this;
		return other.getStrongestBorder(this);
	}

	/**
	 * Split this border in two borders.
	 * 
	 * @return	...
	 * 			| result[0].getSquareAt(getSquareDirections()[0]) = this.getSquareAt(getSquareDirections()[0])
	 * 			| && result[0].getSquareAt(getSquareDirections()[1]) = null
	 * 			| && result[1].getSquareAt(getSquareDirections()[1]) = this.getSquareAt(getSquareDirections()[0])
	 * 			| && result[1].getSquareAt(getSquareDirections()[0]) = null
	 * 			| && result[0].getSlippery() == this.getSlippery()
	 * 			| && result[1].getSlippery() == this.getSlippery()
	 */
	@Override
	public Wall[] split() {
		Square square = getSquareAt(getSquareDirections()[0]);
		removeSquareAt(getSquareDirections()[0]);
		Wall other = new Wall(getSlippery(), square, getSquareDirections()[0]);
		Wall[] borders = new Wall[2];
		borders[0] = other;
		borders[1] = this;
		return borders;
	}

}
